import { SchemaManage } from '@/components/SchemaComponent';
import { ManageCommonAPI } from '@/pages/type';
import { useMemo, useRef } from 'react';
import { connect } from 'umi';
import { warnManageService } from '../services';
import { getTableColumns } from '../mconfig';
import '../common/style.less';
import { commonPageSizeOptions } from '@/common/constVariable';

const WarnManageView: React.FC<WarnManageAPI.IManageType> = ({ curRes }) => {
  /** 管理页ref */
  const schemaManageRef: any = useRef();

  /**  获取管理页数据 */
  const { data, loading, pagination, searchList, getWarnData, reloadRefresh } = warnManageService(curRes);

  /**  重置搜索表单方法 */
  const onReset = (values: any) => {
    getWarnData({ ...values });
  };

  /**  搜索列表 */
  const onSearch = (request: ManageCommonAPI.IGridRequestType) => {
    getWarnData({ ...request });
  };

  /** 分页change 方法 */
  const onPageChange = (current: any, pageSize: any, params: any) => {
    getWarnData({ pageSize, current, ...params });
  };

  /**新增操作按钮*/
  const actionList: any = useMemo(() => {
    return [];
  }, [curRes]);

  /** 获取columns方法 */
  const columns: Record<string, any>[] = useMemo(() => {
    return getTableColumns();
  }, [curRes]);

  return (
    <>
      <div
        className="assetCollectMangeClass_newasset"
        style={{
          position: 'relative',
          overflow: 'hidden',
          height: '100%',
          width: '100%',
        }}
      >
        <SchemaManage
          ref={schemaManageRef}
          searchProps={{
            switchList: [],
            searchList,
            onSwitch: () => {},
            onReset,
            onSearch,
          }}
          actionList={actionList}
          tableProps={{
            columns,
            dataSource: data?.obj?.data,
            loading,
            pagination: {
              showQuickJumper: true,
              showSizeChanger: true,
              pageSizeOptions: commonPageSizeOptions,
              showTotal: (total: any, range: any) => {
                return (
                  <div>
                    <span>
                      <span style={{ fontWeight: 600 }}>资产总数：</span>
                      <span style={{ color: 'red', fontWeight: 600 }}>{data?.obj?.assetTotal ? data?.obj?.assetTotal : '0'}</span>
                    </span>
                    <span style={{ margin: '0 80px' }}>
                      <span style={{ fontWeight: 600 }}>总金额：</span>
                      <span style={{ color: 'red', fontWeight: 600 }}>{data?.obj?.totalAmount ? data?.obj?.totalAmount : '0'}</span>
                    </span>
                  </div>
                );
              },
              pageSize: pagination?.pageSize,
              current: pagination?.current,
              total: pagination?.total,
              showTitle: false,
            },
            rowKey: 'assetClassCode',
            onPageChange, //分页onchange
          }}
        />
      </div>
    </>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
}))(WarnManageView);
